package com.xunge.mapper;

import com.xunge.pojo.Grade;
import com.xunge.pojo.GradeQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface GradeMapper {

    /**
     * 分页查询成绩信息
     */
    List<Grade> list(GradeQueryParam gradeQueryParam);

    /**
     * 新增成绩
     */
    @Insert("insert into grade(student_id, course_id, clazz_id, score, grade_type, semester, remark, create_time, update_time) " +
            "values(#{studentId}, #{courseId}, #{clazzId}, #{score}, #{gradeType}, #{semester}, #{remark}, now(), now())")
    void insert(Grade grade);

    /**
     * 根据ID查询成绩
     */
    @Select("select * from grade where id = #{id}")
    Grade getById(Integer id);

    /**
     * 根据ID修改成绩
     */
    void update(Grade grade);

    /**
     * 根据ID删除成绩
     */
    @Delete("delete from grade where id = #{id}")
    void deleteById(Integer id);

    /**
     * 批量删除成绩
     */
    void deleteByIds(List<Integer> ids);

    /**
     * 根据学生ID查询成绩
     */
    @Select("select * from grade where student_id = #{studentId}")
    List<Grade> getByStudentId(Integer studentId);

    /**
     * 根据课程ID查询成绩
     */
    @Select("select * from grade where course_id = #{courseId}")
    List<Grade> getByCourseId(Integer courseId);

    @MapKey("name")
    List<Map<String, Object>> countGradeDistribution(@Param("gradeType") int gradeType, @Param("semester") String semester);

    /**
     * 获取所有学期
     * @return 学期列表
     */
    List<String> getSemesters();
}